package servlet.admin;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.UserAttr;
import servlet.ServletTemplate;

import dao.UserDao;

public class UserList extends ServletTemplate{
    /**
     * 执行POST操作 
     */
    public void doPost(HttpServletRequest request,
                         HttpServletResponse response) throws IOException, ServletException{
        super.doPost(request, response);
         
        if(false == this.isLogin() || false == this.isAdmin()) {
            this.setRequestAttr("errorInfo", "非法访问！");
            this.forward("hint.jsp");
            return ;
        }
        
        UserDao userDao     = new UserDao();
        if(true == userDao.select()) {
            ArrayList<UserAttr> users     = userDao.fetchAll();
            this.setRequestAttr("users", users);
        }
        
        this.forward("./userlist.jsp");
    }
}
